package com.saudidentalapp;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.saudiapp.lazylist.ImageLoader;
import com.saudiapp.webservice.Constants;
import com.saudiapp.webservice.Responce;
import com.saudiapp.webservice.Utilities;
import com.saudiapp.webservice.Utilities.RatingDialogListener;
import com.saudiapp.webservice.WebServiceManager;
import com.saudiapp.webservice.WebServiceManager.WebServiceListener;
import com.saudidentalapp.datamodels.Exhibitor;

public class AboutExbitor extends Activity implements WebServiceListener ,OnClickListener
{
	TextView txtName,txtDesignation,txtDescription;
	ImageView imgImage;
	TextView txtwebsite,txtphone;	
	ImageView imgFacebook,imgTwitter,imgLinkedn,imgWeb,imgContact;
	
	Utilities utilities;
	
	ImageView imgEmail,imgRating,ximgComment;
	
	Exhibitor exhibitor;
	AboutExbitor activity=this;
	 @Override
	protected void onCreate(Bundle savedInstanceState) 
	 {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_about_exibitors);			
		txtName=(TextView)findViewById(R.id.xtxtName);
		txtDesignation=(TextView)findViewById(R.id.xtxtDesignation);
		txtDescription=(TextView)findViewById(R.id.xtxtDescription);		
		imgImage=(ImageView)findViewById(R.id.ximgspeakerImage);
		
		setView();
	}
	 
	private void setView()
	{
		exhibitor=(Exhibitor) getIntent().getSerializableExtra("MyClass");
		
		txtName.setText(exhibitor.getName());
		txtDesignation.setText(exhibitor.getDesignation());
		txtDescription.setText(exhibitor.getDescription());
		ImageLoader loader= new ImageLoader(activity);
		loader.DisplayImage(exhibitor.getImage(),imgImage);
		
		
		
		
		
		
		txtwebsite=(TextView)findViewById(R.id.xtxtweb);		
		txtphone=(TextView)findViewById(R.id.xtxtcontact);
		
		
		imgWeb=(ImageView)findViewById(R.id.ximgweb);
		imgContact=(ImageView)findViewById(R.id.ximgcall);
		imgFacebook=(ImageView)findViewById(R.id.ximg_fb);
		imgTwitter=(ImageView)findViewById(R.id.ximg_tw);
		imgLinkedn=(ImageView)findViewById(R.id.ximg_in);
	
		if(exhibitor.getWebsite()!=null)
		{
			if(exhibitor.getWebsite().equalsIgnoreCase("#") && exhibitor.getWebsite().equalsIgnoreCase(" "))
			{	imgWeb.setTag(""+exhibitor.getWebsite());
				txtwebsite.setText(exhibitor.getWebsite());
			}
		}
		else
		{
			txtwebsite.setText(""+Constants.DATA_NOT_AVAILABELE);
		}
		
		
		if(exhibitor.getContactNo()!=null)
		{
			if(exhibitor.getContactNo().equalsIgnoreCase("#")&& exhibitor.getContactNo().equalsIgnoreCase(" "))
			{	imgContact.setTag(""+exhibitor.getContactNo());
				txtphone.setText(exhibitor.getContactNo());
			}
		}
		else
		{
			txtphone.setText(""+Constants.DATA_NOT_AVAILABELE);
		}
		
		
		
		
		
		imgFacebook.setTag(""+exhibitor.getFacebookURL());
		imgTwitter.setTag(""+exhibitor.getTwitterURL());
		imgLinkedn.setTag(""+exhibitor.getLinkedInURL());
		
		imgWeb.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0)
			{
				if(arg0.getTag()!=null)
				{
					startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(arg0.getTag().toString())));
				}
				
			}
		});
		
		imgContact.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View arg0) 
					{
						if(arg0.getTag()!=null)
						{
							startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse(arg0.getTag().toString())));
						}
						
					}
				});
		
		imgFacebook.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View arg0) {
						if(arg0.getTag()!=null)
						{
							startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(arg0.getTag().toString())));
						}
						
					}
				});
		
		imgTwitter.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(arg0.getTag()!=null)
				{
					startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(arg0.getTag().toString())));
				}
				
			}
		});
		
		imgLinkedn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(arg0.getTag()!=null)
				{
					startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(arg0.getTag().toString())));
				}
				
			}
		});
		
		
		
		
		
		
		
		
		
		
		//contact information and feedback
			
		imgEmail=(ImageView)findViewById(R.id.ximgEmail);
		imgRating=(ImageView)findViewById(R.id.ximgRating);
		ximgComment=(ImageView)findViewById(R.id.ximgComment);
		
		imgEmail.setOnClickListener(this);
		imgRating.setOnClickListener(this);
		ximgComment.setOnClickListener(this);
		
		utilities=Utilities.getInstance(activity);
		
		final Activity activity=this;
		ImageView imgBack=(ImageView)findViewById(R.id.xbtnVwBack);
		imgBack.setOnClickListener(new OnClickListener() 
		{
			
			@Override
			public void onClick(View arg0) 
			{
				finish();
				startActivity(new Intent(activity,TabActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
				
			}
		});
		
	}

	@Override
	public void onProcesCompleted(int requestId, Object Data) 
	{	
		utilities.dismiss();
		if(((Responce)Data).getResponceData().toString().equals("Success"))
			utilities.showToast("Thanks for rating ....");
	}

	@Override
	public void onErrorOccured(int requestId) 
	{
		utilities.dismiss();	
		utilities.showToast("Error Occured Please try Later...");
		
	}

	@Override
	public void onClick(View v) 
	{
		if(v==imgEmail)
		{
			utilities.sendEmail(exhibitor.getEmail(), "Subject", "");
		}
		else if(v==imgRating)
		{
			utilities.showRatingDialog("Rate Exibitors","Please rate exibitors",exhibitor.getID());
			utilities.setRatingDialogListener(new RatingDialogListener() 
			{
				
				@Override
				public void OnRatingSet(float rating, int id) 
				{
					WebServiceManager webServiceManager=new WebServiceManager(activity);
					webServiceManager.setonWebServiceListener(activity);
					webServiceManager.SetExhibitorRate(id, rating);
					
				}
				
				@Override
				public void OnRatingCancelled()
				{
					// TODO Auto-generated method stub
					
				}
			});
		}
		else if(v==ximgComment)
		{
		
		}
		
	}
	 
}

